import type {
  CreateCrudOptionsProps,
  CreateCrudOptionsRet,
} from '@fast-crud/fast-crud';

import type { DefUserModel } from '#/api';

import { ref } from 'vue';

import { DefUserApi } from '#/api/devOperation/tenant/defUser';
import { DictEnum } from '#/enums/commonEnum';
import { $t } from '#/locales';
import {
  backendDict,
  createdTimeColumn,
  indexColumn,
} from '#/plugins/fast-crud/common';

export function createCrudOptions(
  props: CreateCrudOptionsProps<DefUserModel.DefUserResultVO, any>,
): CreateCrudOptionsRet<DefUserModel.DefUserResultVO> {
  const selectedRowKeys = ref<string[]>([]);

  return {
    selectedRowKeys,
    crudOptions: {
      search: { show: false },
      request: { pageRequest: DefUserApi.pageFindNotUserByTenantId },
      actionbar: {
        buttons: {
          add: { show: false },
        },
      },
      table: {
        striped: true,
        rowKey: 'id',
        rowSelection: {
          type: 'checkbox',
          selectedRowKeys,
          onChange: (changed: string[]) => {
            selectedRowKeys.value = changed;
          },
        },
      },
      rowHandle: {
        show: false,
        buttons: {
          copy: { show: false },
          view: { show: false },
          edit: { show: false },
          remove: { show: false },
        },
      },
      columns: {
        ...indexColumn(props.crudExpose),
        username: {
          title: $t('devOperation.tenant.defUser.username'),
          type: 'text',
          search: { show: true },
        },
        nickName: {
          title: $t('devOperation.tenant.defUser.nickName'),
          type: 'text',
          search: { show: true },
        },
        email: {
          title: $t('devOperation.tenant.defUser.email'),
          type: 'text',
          search: { show: true },
        },
        mobile: {
          title: $t('devOperation.tenant.defUser.mobile'),
          type: 'text',
          search: { show: true },
        },
        idCard: {
          title: $t('devOperation.tenant.defUser.idCard'),
          type: 'text',
          search: { show: true },
        },
        sex: {
          title: $t('devOperation.tenant.defUser.sex'),
          type: 'dict-select',
          dict: backendDict(DictEnum.Sex),
        },
        ...createdTimeColumn({}),
      },
    },
  };
}
